package com.tanhua.mysqldb.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.api.service.UserApi;
import com.tanhua.model.pojo.User;
import com.tanhua.mysqldb.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        return userMapper.selectOne(
                Wrappers.lambdaQuery(User.class)
                        .eq(User::getMobile, mobile)
        );
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.update(user, Wrappers.lambdaUpdate(User.class)
                .eq(User::getId, user.getId()));
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    @Override
    public User findByUserId(Long userId) {
        return userMapper.selectOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getId, userId));
    }

    @Override
    public User findByHxUser(String huanxinId) {
        return userMapper.selectOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getHxUser, huanxinId));
    }
}
